package com.glink.mydemo;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;



import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.Button;

import com.baize.glinkad.bean.listener.ADListener;
import com.baize.glinkad.manager.GLinkADManager;


public class MainActivity extends Activity {
    private Button splash,banner, intertital, video, other;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        splash = (Button) findViewById(R.id.splash);
        banner = (Button) findViewById(R.id.banner);
        intertital = (Button) findViewById(R.id.intertitial);
        video = (Button) findViewById(R.id.video);
        other = (Button) findViewById(R.id.other);


       // getAAID(this);
        splash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, SplashActivity.class);
                startActivity(intent);
            }
        });

        banner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, BannerActivity.class);
                startActivity(intent);
            }
        });

        intertital.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, InterstitialActivity.class);
                startActivity(intent);
            }
        });

        video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setClass(MainActivity.this, VideoActivity.class);
                startActivity(intent);
            }
        });
        other.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


        //申请权限   READ_PHONE_STATE       WRITE_EXTERNAL_STORAGE
        try {

            //check权限
            if ((ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED)
                    || (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
                //没有 ，  申请权限  权限数组
                ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.READ_PHONE_STATE ,Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
            } else {
                GLinkADManager.init(MainActivity.this, new ADListener() {
                    @Override
                    public void Success() {

                    }

                    @Override
                    public void Failed(String msg) {

                    }
                });
            }
        } catch (Exception e) {

        }





    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            GLinkADManager.init(MainActivity.this, new ADListener() {
                @Override
                public void Success() {

                }

                @Override
                public void Failed(String msg) {

                }
            });
        }else{

        }
    }
    /**
     * GET test deviceId for facebook ads
     * @param context
     */
/*    public void getAAID(final Context context){
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                //get AAID
                try {
                    String ss=AdvertisingIdClient.getAdvertisingIdInfo(context).getId();
                    ADLog.log_I(ss);
                } catch (Exception e) {
                    ADLog.log_E(e.toString());
                }

            }
        });
        thread.start();
    }*/


}
